using Microsoft.Xna.Framework;

namespace RunGun
{
    /// <summary>
    /// Abstract base class that declares the objects and functions for the game camera.
    /// </summary>
    public abstract class CameraBase
    {
        /// <summary>
        /// The world matrix
        /// </summary>
        public readonly Matrix World;

        /// <summary>
        /// The projection matrix
        /// </summary>
        public readonly Matrix Projection;

        /// <summary>
        /// The position of the camera
        /// </summary>
        protected Vector3 position;

        /// <summary>
        /// The target the camera looks at
        /// </summary>
        protected Vector3 target;

        /// <summary>
        /// The y rotation of the camera
        /// </summary>
        protected Vector3 yRotation;

        /// <summary>
        /// Initializes a new instance of the <see cref="CameraBase"/> class.
        /// </summary>
        protected CameraBase()
        {
            Position = new Vector3(0, 5, 10);
            Target = new Vector3(0, 0, 0);
            YRotation = new Vector3(0, 1, 0);
            World = Matrix.CreateTranslation(0, 0, 0);
            View = Matrix.CreateLookAt(Position, Target, YRotation);
            Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45), 800f/600f, 0.1f, 1000f);
        }

        /// <summary>
        /// The view matrix
        /// </summary>
        public Matrix View { get; protected set; }

        /// <summary>
        /// Gets or sets the position.
        /// </summary>
        public Vector3 Position 
        { 
            get { return position; }
            set 
            { 
                position = value;
                View = Matrix.CreateLookAt(position, target, yRotation);
            }
        }

        /// <summary>
        /// Gets or sets the target.
        /// </summary>
        public Vector3 Target
        {
            get { return target; }
            set
            {
                target = value;
                View = Matrix.CreateLookAt(position, target, yRotation);
            }
        }

        /// <summary>
        /// Gets or sets the Y rotation.
        /// </summary>
        /// <value>
        /// The Y rotation.
        /// </value>
        public Vector3 YRotation
        {
            get { return yRotation; }
            set
            {
                yRotation = value;
                View = Matrix.CreateLookAt(position, target, yRotation);
            }
        }
    }
}